﻿using System;
using System.Text;
using System.IO;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using webapp4U;
using webapp4U.BOL;

namespace webapp4U.UI
{
    public partial class Address : BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            lblTitle.Text = "Cập Nhật Bảng Giá vàng";

            if (!Page.IsPostBack)
            {
                Load_w4u_BangGiaVang();
            }
        }


        private void Load_w4u_BangGiaVang()
        {
            // load bang gia vang
            DataSet ds = ClassData.ReturnDataSet("select * from w4u_BangGiaVang", "table");
            GridViewItem.DataSource = ds;
            GridViewItem.DataBind();
        }

        protected void btSave_Click(object sender, EventArgs e)
        {

            //xoa bang gia
            ClassData.ExecuteSQL("delete from w4u_BangGiaVang");

            // StringBuilder object
            StringBuilder str = new StringBuilder();
            // Select the checkboxes from the GridView control
            for (int i = 0; i < GridViewItem.Rows.Count; i++)
            {
                GridViewRow row = GridViewItem.Rows[i];
                string VangID = ((TextBox)row.FindControl("txtVangID")).Text.Trim();
                string Muavao = ((TextBox)row.FindControl("txtMuavao")).Text.Trim();
                string Banra = ((TextBox)row.FindControl("txtBanra")).Text.Trim();

                string SQL = string.Format("insert into w4u_BangGiaVang(VangID,Muavao,Banra) values('{0}','{1}','{2}')",VangID,Muavao,Banra);
                //string SQL = string.Format("Update w4u_BangGiaVang set VangID = '{0}',Muavao = '{1}',Banra = '{2}' Where VangID = '{3}' ",VangID,Muavao,Banra,VangID);
                //Response.Write("<br>" + SQL);
                ClassData.ExecuteSQL(SQL);
            }

            lblMsg.Text = "Cập nhật bảng giá vàng thành công";

            Load_w4u_BangGiaVang();
        }
       
    }
}